#include "hfloatingdialog.h"



HFloatingDialog::HFloatingDialog(QWidget *parent) :
    QMessageBox(parent),
    mDuration(3000)
{
    setWindowFlags(Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint);
    setStandardButtons(QMessageBox::NoButton);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    setAttribute(Qt::WA_DeleteOnClose);

    connect(&mTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    mTimer.setSingleShot(true);
    mTimer.setInterval(mDuration);
    setModal(false);
}

void HFloatingDialog::setDuration(int msec)
{
    mTimer.setInterval(msec);
}

void HFloatingDialog::show()
{
    QWidget* w = parentWidget();
    if (w) {
        move(10, w->height() - 50 - height());
    }

    mTimer.start();
    QMessageBox::exec();
}

void HFloatingDialog::exec()
{
    show();
}

void HFloatingDialog::onTimeout()
{
    this->accept();
}
